﻿/* 
 * BtCommLib - the OpenWebNet .NET Library
 *
 * Copyright (C) 2011 BTicino S.p.A.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BTicino.BtCommLib.Exceptions;

namespace BTicino.BtCommLib.Communication
{
    public sealed class BTCommMgr
    {
        #region Singleton management
        /// <summary>
        /// Singleton Mgmt
        /// </summary>
        private static readonly BTCommMgr instance = new BTCommMgr();
        
        /// <summary>
        /// Empty constructor
        /// </summary>
        private BTCommMgr() { }

        public static BTCommMgr Instance
        {
            get
            {
                return instance;
            }
        }
        //End Singleton Mgmt
        #endregion

        /// <summary>
        /// Gives back a new communication channel, starting from ChanTypes
        /// </summary>
        /// <param name="theChanType">Channel Type (eg. Open, ect...</param>
        /// <returns> I resturns an IBTCommChan concrete object instance or LibException if some errors occurred</returns>
        public IBTCommChan getCommChan(BTChanTypes theChanType)
        {
            switch (theChanType)
            {
                case BTChanTypes.Open:
                    return new BTOpenCommChan();
                default:
                    throw new LibException("Chan Type not found!");
            }
        }
    }
}
